package chapter03.s07static.example15;
// static

// 2. 静态方法
class Student {
    private String name;                                // 定义name属性
    private int age;                                    // 定义age属性
    private static String school = "A大学";              // 定义school属性 静态属性

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void info() {
        System.out.println("姓名:" + this.name + "，年龄:" + this.age + "，学 校:" + school);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // 定义静态方法
    public static String getSchool() {
        // 访问静态属性，通过 类名.属性 来调用
        return Student.school;
    }

    public static void setSchool(String school) {
        // 访问静态属性，通过 类名.属性 来调用
        Student.school = school;
    }
}

class Example15 {
    public static void main(String[] args) {
        Student stu1 = new Student("张三", 18);      // 创建学生对象
        Student stu2 = new Student("李四", 19);
        Student stu3 = new Student("王五", 20);
        stu1.setAge(20);
        stu2.setName("小明");

        // 访问静态方法，通过 类名.方法 来调用
        Student.setSchool("B大学");

        stu1.info();
        stu2.info();
        stu3.info();
    }
}
